<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="-1">
<title>渠道后台报表</title>

<link rel="stylesheet" type="text/css" href="jquery-ui.min.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<script type="text/javascript" src="jquery-1.6.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
.easyui-layout {
	padding: 0;
	margin: 0;
}

.datagrid-header-row {
	height: 40px;
}

.datagrid-cell {
	font-size: 20px;
}

.FormTextTitle {
	color: #666666;
	line-height: 19px;
	overflow: hidden;
	width: 100px;
	text-align: right
}
 .one{  
              
                visibility:hidden;  
            }  
           
</style>
</head>
<body>

	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north'" style="height:50px">
			<div class="span12">
				<h1 class="text-center">渠道后台报表</h1>
			</div>
		</div>
		<div data-options="region:'west',split:true" title=""
			style="width:200px;" draggable="false">
			<div style="margin-left: 10px;margin-top: 20px;"><h4>游戏名称:</h4></div>
    <select id="gameStype" class="combobox"name="state" style="width:150px;margin-left: 10px;" >
	</select>
	<div id = "hide">
   <div style="margin-left: 10px;margin-top: 30px;"><h4>渠道分成比:</h4></div>
	<input name ="demo" type="text" placeholder="渠道分成比"  style="width:135px;margin-left: 10px;" id="quZhan" value=60 />%
		  <div style="margin-left: 10px;margin-top: 30px;"><h4>分成基数:</h4></div>
			 <div style="margin-left: 10px;margin-top: 30px;">	
			 <select  id = "selectji" >
               <option name ="sele" value="1">总付费金额</option>
                <option name ="sele"value="2">总净收益</option>
             </select>
   </div>
   
   </div>
   <div id ="check" hidden="true" class ="one">
   
    <div style="margin-left: 10px;margin-top: 30px;"><h4>需要隐藏的列:</h4></div>
   <input type="checkbox" name="BUSINESSSCOPE" id = "installid" value="install" />新增用户    &nbsp
     &nbsp
   <input type="checkbox" name="BUSINESSSCOPE" id = "totalmoneyid" value="totalmoney" />总付费金额   &nbsp   
   <input type="checkbox" name="BUSINESSSCOPE" id = "arpuid" value="arpu" />ARUP &nbsp
     &nbsp  &nbsp
   <input type="checkbox" name="BUSINESSSCOPE" id = "totalrevenueid" value="totalrevenue" /> 总净收益   &nbsp 
   <input type="checkbox" name="BUSINESSSCOPE" id = "channelmoneyid" value="channelmoney" />渠道分成 &nbsp  &nbsp
   <input type="checkbox" name="BUSINESSSCOPE" id = "cpmoneyid" value="cpmoney" />CP分成
   <input type="button" id="confirm" width="12" value="确定"  onclick="oo()"/>

   </div>
   
    <div id ="xishubase" hidden="true" class ="one">
   
    <div style="margin-left: 10px;margin-top: 30px;"><h4>系数设置:</h4></div>
   <div style="margin-left: 10px;margin-top: 30px;" ><h4>新增用户系数 :</h4></div>
   <input type="text" name="coefficent" id="installcoeff" style="width:135px;margin-left: 10px;"value = "100" />  % 
     <div style="margin-left: 10px;margin-top: 30px;"><h4>总付费金额系数 :</h4></div>
   <input type="text" name="coefficent" id="totalmoneycoeff" style="width:135px;margin-left: 10px;"value = "100" />%   
     <div style="margin-left: 10px;margin-top: 30px;"><h4>系数基  (新增用户数>=):</h4></div>
   <input type="text" name="coefficent" id="coeffbase" style="width:135px;margin-left: 10px;" value = "0"/>
   <input type="button" id="confirm" width="12" value="确定"  onclick="clickbase()"/>
   </div>
		</div>
		<div data-options="region:'center',title:'',iconCls:'icon-ok'" >
			<div data-options="region:'center'" draggable="false">
				<table data-toggle="table" id="videoList"></table>
			</div>
			<div data-options="region:'south'" style="height:100px" title="">
				<form>
					<table width="100%" border="0" cellspacing="3" cellpadding="0">
						<tr>
							<td class="FormTextTitle"><h5>新增用户:</h5></td>
							<td><input type="text" id="TsumInstall" value="0" readonly="readonly" /></td>
							<td class="FormTextTitle"><h5>总付费金额:</h5></td>
							<td><input type="text" id="Ttotalmoney" value="0"  readonly="readonly" /></td>
							<td class="FormTextTitle"><h5>AUPR:</h5></td>
							<td><input type="text" id="Tarup" value="0"  readonly="readonly"/></td>
						</tr>
						<tr>
							<td class="FormTextTitle"><h5>总收益:</h5></td>
							<td><input type="text" id="Ttotalrevenue" value="0"  readonly="readonly"/></td>
							<td class="FormTextTitle"><h5>渠道分成:</h5></td>
							<td><input type="text" id="Tchannelmoney" value="0"  readonly="readonly"/></td>
							<td class="FormTextTitle"><h5>CP分成:</h5></td>
							<td><input type="text" id="Tcpmoney" value="0" readonly="readonly" /></td>
						</tr>
					</table>
				</form>
				
			</div>

		</div>

	</div>
	<script type="text/javascript">
		var width = document.body.clientWidth - 165;
		var height = document.body.clientHeight;
		var channelId = "${channelId}";
		var password = "${channelPassword}";
		var qx;
		var arrayClume = ["install","totalmoney","arpu","totalrevenue","channelmoney","cpmoney"];
		var rideclume = "${rideclunme}";
		var arrayObj ;
		function oo(){
			var isc = "";
            $("input[name='BUSINESSSCOPE']:checked").each(function () { //遍历table里的全部checkbox
              isc += $(this).val() + ","; //获取被选中的值
            });
            alert(isc);
            $.ajax({
                type: "post", //以post方式与后台沟通
                url : "saveHidden?channelId="+channelId+"&appkey="+$('#gameStype').combobox('getValue')+"&isc="+isc,                
                success: function(json){
                	
                }
            });
          
           // $("#videoList").datagrid('reload');
		}
		function clickbase(){
		
            $.ajax({
                type: "post", //以post方式与后台沟通
                url : "savexishuBase?channelId="+channelId+"&appkey="+$('#gameStype').combobox('getValue')+"&installcoeff="+$("#installcoeff").val()+"&totalmoneycoeff="+$("#totalmoneycoeff").val()+"&coeffbase="+$("#coeffbase").val(), 
                success: function(json){
                	  $("#videoList").datagrid('reload');
                }
            });
		}
		
		
		 var games  ;
		$(document).ready(function() {
			//获取表格数据url
			 if(password=="123456"||rideclume) {
	  		    // $("#hide").hide();
	  			 $("input[name=demo]").attr("readonly","readonly");
	  			 $("option[name=sele]").attr("disabled","disabled");
	  			 $("#check").hide();
	  			 $("#xishubase").hide();
	  			 }
			 else{
				 var d=document.getElementById('check');
				 d.style.visibility="visible";
				 var c=document.getElementById('xishubase');
				 c.style.visibility="visible";
				 $("#check").show();
	  			 $("#xishubase").show();
			 }
			 var quzhanv = $("#quZhan").val();
		     var jiv = $('#selectji option:selected').val();
			 var url="getData?channelId="+channelId+"&quZhan="+$("#quZhan").val()+"&password="+password+"&ji="+jiv;
			  $('#selectji').combobox({
					
		
					onChange: function (n,o) {
						
						
						  games =  $('#gameStype').combobox('getValue');
						  jiv = n;
						  url="getData?channelId="+channelId+"&quZhan="+quzhanv+"&password="+password+"&ji="+jiv+"&appkey="+games;
						 	
						 
						  $('#videoList').datagrid('options').url=url;
						  $("#videoList").datagrid('reload');

						    $("#TsumInstall").val(0);
							$("#Ttotalmoney").val(0);
							$("#Tarup").val(0);
							$("#Ttotalrevenue").val(0);
							$("#Tchannelmoney").val(0);
							$("#Tcpmoney").val(0);
						  }
					}); 
			 
			  $('#quZhan').numberbox({
			        min:0,
			        precision:2,
			        max:100,
			        onChange:function(n,o)
			        {   
			        	
			        
			        	 games = $('#gameStype').combobox('getValue');
			        	 quzhanv = n;
			        	 url="getData?channelId="+channelId+"&quZhan="+n+"&password="+password+"&ji="+jiv+"&appkey="+games;
					 	
			        	// url="getData?channelId="+channelId+"&quZhan="+n+"&appkey="+$('#gameStype').attr("value");
			        	 $('#videoList').datagrid('options').url=url;
			        	 $("#videoList").datagrid('reload');
			        //	 $("#Tchannelmoney").val((parseFloat($("#Ttotalrevenue").val())*parseFloat($("#quZhan").val())/100).toFixed(2));
					//	 $("#Tcpmoney").val((parseFloat($("#Ttotalrevenue").val())-parseFloat($("#Tchannelmoney").val())).toFixed(2));		
						 
						    $("#TsumInstall").val(0);
							$("#Ttotalmoney").val(0);
							$("#Tarup").val(0);
							$("#Ttotalrevenue").val(0);
							$("#Tchannelmoney").val(0);
							$("#Tcpmoney").val(0);
			        }
			        }
			    ); 
			
		
			$("#videoList").datagrid({
				fitColumns : true,
				pagination : true,
				pageSize : 20,
				pageList: [20, 30, 40, 50, 400],
				rownumbers : true,
				width : width,
				height : document.body.clientHeight - 200,
				singleSelect : false,
				method : 'get',
				url:url,
				rownumbers : true,
				onSelect:function(ri,rd){
					
					$("#TsumInstall").val(0);
					$("#Ttotalmoney").val(0);
					$("#Tarup").val(0);
					$("#Ttotalrevenue").val(0);
					$("#Tchannelmoney").val(0);
					$("#Tcpmoney").val(0);
					var rows = $("#videoList").datagrid('getSelections');
					
					for(var i = 0;i<rows.length;i++){
						
						var osumInstall =$("#TsumInstall").val();;
						$("#TsumInstall").val(parseInt(rows[i].install)+parseInt(osumInstall));
						
						var ototalmoney =$("#Ttotalmoney").val();
						$("#Ttotalmoney").val((parseFloat(rows[i].totalmoney)+parseFloat(ototalmoney)).toFixed(2));
						
						//var oarup =$("#Tarup").val();
				         
					
						//$("#Tarup").val((parseFloat($("#Ttotalmoney").val())/parseInt($("#TsumInstall").val())).toFixed(2));
						var ototalrevenue =$("#Ttotalrevenue").val();
						
						$("#Ttotalrevenue").val((parseFloat(rows[i].totalrevenue)+parseFloat(ototalrevenue)).toFixed(2));
						var ochannelmoney =$("#Tchannelmoney").val();
						
						$("#Tchannelmoney").val((parseFloat(rows[i].channelmoney)+parseFloat(ochannelmoney)).toFixed(2))
						var ocpmoney =$("#Tcpmoney").val();
						
						$("#Tcpmoney").val((parseFloat(rows[i].cpmoney)+parseFloat(ocpmoney)).toFixed(2))
					}
					if(rows.length==1)
						{
						$("#Tarup").val(rows[0].arpu);
						}
					if(rows.length>=2)
						{
						if(rows[rows.length-1].dataTime>rows[0].dataTime)
							$("#Tarup").val(rows[rows.length-1].arpu);
							else
							$("#Tarup").val(rows[0].arpu);
						
						}
				/* 	var rws = $("#videoList").datagrid("getRows"); 
					if(rws.length>0)
					$("#Tarup").val(rws[0].arpu); */
					
				},
				onUnselect:function(ri,rd){
					$("#TsumInstall").val(0);
					$("#Ttotalmoney").val(0);
					$("#Tarup").val(0);
					$("#Ttotalrevenue").val(0);
					$("#Tchannelmoney").val(0);
					$("#Tcpmoney").val(0);
					var rows =$("#videoList").datagrid('getSelections');
                    for(var i = 0;i<rows.length;i++){
						
						var osumInstall =$("#TsumInstall").val();;
						$("#TsumInstall").val(parseInt(rows[i].install)+parseInt(osumInstall));
						
						var ototalmoney =$("#Ttotalmoney").val();
						$("#Ttotalmoney").val((parseFloat(rows[i].totalmoney)+parseFloat(ototalmoney)).toFixed(2));
						
						//var oarup =$("#Tarup").val();
				        
					   
						//$("#Tarup").val((parseFloat($("#Ttotalmoney").val())/parseInt($("#TsumInstall").val())).toFixed(2));
						var ototalrevenue =$("#Ttotalrevenue").val();
						
						$("#Ttotalrevenue").val((parseFloat(rows[i].totalrevenue)+parseFloat(ototalrevenue)).toFixed(2));
						var ochannelmoney =$("#Tchannelmoney").val();
						
						$("#Tchannelmoney").val((parseFloat(rows[i].channelmoney)+parseFloat(ochannelmoney)).toFixed(2))
						var ocpmoney =$("#Tcpmoney").val();
						
						$("#Tcpmoney").val((parseFloat(rows[i].cpmoney)+parseFloat(ocpmoney)).toFixed(2))
					}
                	if(rows.length==1)
					{
					$("#Tarup").val(rows[0].arpu);
					}
				if(rows.length>=2)
					{
					 if(rows[rows.length-1].dataTime>rows[0].dataTime)
						$("#Tarup").val(rows[rows.length-1].arpu);
						else
						$("#Tarup").val(rows[0].arpu);
					
					}
			/* 	var rws = $("#videoList").datagrid("getRows"); 
				if(rws.length>0)
				$("#Tarup").val(rws[0].arpu); */
					
				},
				onSelectAll:function(rows){
					$("#TsumInstall").val(0);
					$("#Ttotalmoney").val(0);
					$("#Tarup").val(0);
					$("#Ttotalrevenue").val(0);
					$("#Tchannelmoney").val(0);
					$("#Tcpmoney").val(0);
				
                 for(var i = 0;i<rows.length;i++){
						
						var osumInstall =$("#TsumInstall").val();;
						$("#TsumInstall").val(parseInt(rows[i].install)+parseInt(osumInstall));
						
						var ototalmoney =$("#Ttotalmoney").val();
						$("#Ttotalmoney").val((parseFloat(rows[i].totalmoney)+parseFloat(ototalmoney)).toFixed(2));
						
						//var oarup =$("#Tarup").val();
				
					
					//	$("#Tarup").val((parseFloat($("#Ttotalmoney").val())/parseInt($("#TsumInstall").val())).toFixed(2));
						var ototalrevenue =$("#Ttotalrevenue").val();
						
						$("#Ttotalrevenue").val((parseFloat(rows[i].totalrevenue)+parseFloat(ototalrevenue)).toFixed(2));
						var ochannelmoney =$("#Tchannelmoney").val();
						
						$("#Tchannelmoney").val((parseFloat(rows[i].channelmoney)+parseFloat(ochannelmoney)).toFixed(2))
						var ocpmoney =$("#Tcpmoney").val();
						
						$("#Tcpmoney").val((parseFloat(rows[i].cpmoney)+parseFloat(ocpmoney)).toFixed(2))
					}
             	if(rows.length==1)
				{
				$("#Tarup").val(rows[0].arpu);
				}
			if(rows.length>=2)
				{
				if(rows[rows.length-1].dataTime>rows[0].dataTime)
					$("#Tarup").val(rows[rows.length-1].arpu);
					else
					$("#Tarup").val(rows[0].arpu);
				
				}
			/* var rws = $("#videoList").datagrid("getRows"); 
			if(rws.length>0)
			$("#Tarup").val(rws[0].arpu); */
				},
				onUnselectAll:function(rows){
					$("#TsumInstall").val(0);
					$("#Ttotalmoney").val(0);
					$("#Tarup").val(0);
					$("#Ttotalrevenue").val(0);
					$("#Tchannelmoney").val(0);
					$("#Tcpmoney").val(0);
					
				},
				
				columns : [[{
					field : 'ck',
					checkbox : true,
					
				}, {
					field : 'dataTime',
					title : '日期',
					width : width * 0.1,
					sortable: true,
					align : 'center'
					
				}, {
					field : 'install',
					title : '新增用户',				   
					
					width : width * 0.1,
					align : 'center'
						
				}, {
					field : 'totalmoney',
					title : '总付费金额',
					width : width * 0.1,
					
					align : 'center'
						
				}, {
					field : 'arpu',
					title : 'AUPR',
				
					width : width * 0.1,
					align : 'center'
						
				}, {
					field : 'totalrevenue',
					title : '总净收益',
					
					width : width * 0.1,
					align : 'center'
						
				}, {
					field : 'channelmoney',
					title : '渠道分成',
					
					width : width * 0.1,
					align : 'center'
					
				}, {
					field : 'cpmoney',
					title : 'CP分成',
				
					width : width * 0.1,
					align : 'center'
						
				},
				{
					field : 'factcpmoney',
					title : 'factcp',
					styler: function (value, row, index) {
			              return 'background-color:red;color:white';
			           },
					width : width * 0.1,
					align : 'center'
						
				}
				]]
			});
			$('#gameStype').combobox({
				url:'getGameType?channelId='+channelId,
				valueField:'id',
				textField:'text',
			    onLoadSuccess: function () { //加载完成后,设置选中第一项
	            var val = $(this).combobox("getData");
	            if(password=="123456"||rideclume) 
	            $("#videoList").datagrid('hideColumn','factcpmoney');
	            for (var item in val[0]) {
	            if (item == "id") {
	                        $(this).combobox("select", val[0][item]);
	                        games = $('#gameStype').combobox('getValue');
	                       
	                     
	                    }
	                }
	            $.ajax({
  	              type: "post", //以post方式与后台沟通
  	              url :"getHidden?channelId="+channelId+"&appkey="+games, 
  	              dataType: "text",
  	              success: function(json){
              
  	              arrayObj = json.split(",");
  	          
            		 
  	              for (var item in arrayObj)
  	            	  {
  	            	  if(password == '123456'||rideclume){
  	            	      
  	            		  $("#videoList").datagrid('hideColumn',arrayObj[item]);
  	            	     }
  	            	  else
  	            		  {
  	            		
  	            		  if(arrayObj[item]=='install')
  	            		  $("#installid").attr("checked", true);
  	            		  if(arrayObj[item]=='totalmoney')
      	            		  $("#totalmoneyid").attr("checked", true);
  	            		  if(arrayObj[item]=='arpu')
      	            		  $("#arpuid").attr("checked", true);
  	            		  if(arrayObj[item]=='totalrevenue')
      	            		  $("#totalrevenueid").attr("checked", true);
  	            		  if(arrayObj[item]=='channelmoney')
      	            		  $("#channelmoneyid").attr("checked", true);
  	            		  if(arrayObj[item]=='cpmoney')
      	            		  $("#cpmoneyid").attr("checked", true);
  	            		  $("#videoList").datagrid('showColumn',arrayObj[item]);
  	            		  }
  	            	  }
  	            
  	              }
  	          });
	           
	            },
				onChange: function (n,o) {
				      games = n;
					  url="getData?channelId="+channelId+"&quZhan="+quzhanv+"&password="+password+"&ji="+jiv+"&appkey="+games;
		 
					  $("#videoList").datagrid('options').url=url;
					  $("#videoList").datagrid('reload');

					   $("#TsumInstall").val(0);
					   $("#Ttotalmoney").val(0);
					    $("#Tarup").val(0);
						$("#Ttotalrevenue").val(0);
						$("#Tchannelmoney").val(0);
						$("#Tcpmoney").val(0);
						$.ajax({
					             type: "GET",
					             url: "getCan?channelId="+channelId+"&appkey="+games,				             
					             dataType: "text",
					             success: function(data){
					                        var jiuv = data.split(",")[0];
					                        var biuv = data.split(",")[1];               
					                        $("#quZhan").numberbox("setValue",biuv);					                       
					                        $('#selectji').combobox('setValue',jiuv)
					                        if(password!="123456" && !rideclume ){
					                        $('#installcoeff').val(data.split(",")[2]);
					                        $('#totalmoneycoeff').val(data.split(",")[3]);
					                        $('#coeffbase').val(data.split(",")[4]);
					                        }				             
					                      }
					         });
						 for (var st in arrayClume){
							
		  	            	 $("#videoList").datagrid('showColumn',arrayClume[st]);
		  	            	 }
						     $.ajax({
			  	              type: "post", //以post方式与后台沟通
			  	              url :"getHidden?channelId="+channelId+"&appkey="+games, 
			  	              dataType: "text",
			  	              success: function(json){
			               
			  	              arrayObj = json.split(",");
			  	             
			  	              for (var item in arrayObj)
			  	            	  {
			  	            	  if(password == '123456'||rideclume){
			  	            		
			  	            	     $("#videoList").datagrid('hideColumn',arrayObj[item]);
			  	            	     }
			  	            	  else
			  	            		  {
			  	            		
			  	            		
			  	            		  if(arrayObj[item]=='install')
			  	            		  $("#installid").attr("checked", true);
			  	            		  if(arrayObj[item]=='totalmoney')
			      	            		  $("#totalmoneyid").attr("checked", true);
			  	            		  if(arrayObj[item]=='arpu')
			      	            		  $("#arpuid").attr("checked", true);
			  	            		  if(arrayObj[item]=='totalrevenue')
			      	            		  $("#totalrevenueid").attr("checked", true);
			  	            		  if(arrayObj[item]=='channelmoney')
			      	            		  $("#channelmoneyid").attr("checked", true);
			  	            		  if(arrayObj[item]=='cpmoney')
			      	            		  $("#cpmoneyid").attr("checked", true);
			  	            		  $("#videoList").datagrid('showColumn',arrayObj[item]);
			  	            		  }
			  	            	  }
			  	            
			  	              }
			  	          });
				           
					  }
				}); 
		
			//$('#videoList').datagrid('hideColumn', 'cpmoney');
			
		});
		
		 //$("#videoList").datagrid('hideColumn','cpmoney'); 
		
		
	</script>

</body>
</html>